package ig.metrica.ui.unidadsubcuenta;

import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.util.Collection;
import java.util.Iterator;
import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.swing.BorderFactory;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

import ig.metrica.origenesdedatos.Formato;
import ig.metrica.origenesdedatos.FormatoHome;
import ig.metrica.ui.PantallaSevinproPanel;
import ig.util.ConexionServer;
import ig.util.ejb.IGBean;
import ig.util.ejb.IGLlaveInt;

public class PantallaDatosBasicosUnidad extends PantallaSevinproPanel {

	private JComboBox comboFormato;
	private JTextField txtUnidad;
	private JTextField txtSubcuenta;
	private JTextField txtDescripcion;

    private JComboBox[] comboBoxsColumns=new JComboBox[1];

    @Override
    public JComboBox[] getComboBoxsColumnsTable1() {
        return comboBoxsColumns;
    }

    private JComboBox[] comboBoxsColumnsTable2=new JComboBox[1];
    @Override
    public JComboBox[] getComboBoxsColumnsTable2() {
        return comboBoxsColumnsTable2;
    }

    
	public PantallaDatosBasicosUnidad(){
		JPanel panelSuperior;
		
		setLayout( new BorderLayout() );
		
		//int gridx, int gridy, int gridwidth, int gridheight, double weightx, double weighty, int anchor, int fill, Insets insets, int ipadx, int ipady
		
		add( panelSuperior = new JPanel(), BorderLayout.NORTH );
			panelSuperior.setLayout( new GridBagLayout() );
			panelSuperior.setBorder( BorderFactory.createEmptyBorder(10, 10, 0, 10) );
			//----------
			panelSuperior.add( new JLabel(), new GridBagConstraints(0, 0, 1, 1, 0.4, 0.1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0) );
			panelSuperior.add( new JLabel("Formato"), new GridBagConstraints(1, 0, 1, 1, 0.1, 0.1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0) );
			panelSuperior.add( new JLabel("Unidad de Captura"), new GridBagConstraints(1, 1, 1, 1, 0.1, 0.1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0) );
			panelSuperior.add( new JLabel("Sub-Cuenta"), new GridBagConstraints(1, 2, 1, 1, 0.1, 0.1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0) );
			panelSuperior.add( new JLabel("Descripcion"), new GridBagConstraints(1, 3, 1, 1, 0.1, 0.1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0) );
			panelSuperior.add( new JLabel(), new GridBagConstraints(2, 0, 1, 1, 0.1, 0.1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0) );
			panelSuperior.add( comboFormato = new JComboBox(), new GridBagConstraints(3, 0, 1, 1, 1, 0.1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0) );
			panelSuperior.add( txtUnidad = new JTextField(), new GridBagConstraints(3, 1, 1, 1, 1, 0.1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0) );
			panelSuperior.add( txtSubcuenta = new JTextField(), new GridBagConstraints(3, 2, 1, 1, 1, 0.1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0) );
			panelSuperior.add( txtDescripcion = new JTextField(), new GridBagConstraints(3, 3, 1, 1, 1, 0.1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0) );
			panelSuperior.add( new JLabel(), new GridBagConstraints(4, 0, 1, 1, 0.4, 0.1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0) );

                        txtUnidad.setDisabledTextColor(new java.awt.Color(0, 0, 0));		
                        txtSubcuenta.setDisabledTextColor(new java.awt.Color(0, 0, 0));
                        txtDescripcion.setDisabledTextColor(new java.awt.Color(0, 0, 0));

			Properties prop = new Properties();
			prop.put( Context.INITIAL_CONTEXT_FACTORY, IGBean.INITIAL_CONTEXT_FACTORY);
			
			String Sockec = new ConexionServer().getSocketServer();
			prop.put( Context.PROVIDER_URL, Sockec);
			
			try {
				InitialContext ctx = new InitialContext(prop);
				FormatoHome home = (FormatoHome)ctx.lookup("ig.metrica.origenesdedatos.Formato");
				Collection resultado = home.findByPropiedades("");
				Iterator i = resultado.iterator();

				while(i.hasNext()){
					Formato conexion = (Formato)i.next();
					Object[] registro = new Object[2];
					registro[0] = new Long( ((IGLlaveInt)conexion.getPrimaryKey()).getIdInterna() );
					String temp = new String( new Long( ((IGLlaveInt)conexion.getPrimaryKey()).getIdInterna())+"-"+conexion.getNombre());
					comboFormato.addItem( temp.trim() );
				}
			} catch (Exception e) {
                                JOptionPane.showMessageDialog( this,"Error:"+ e.toString(),"Mensaje",JOptionPane.OK_CANCEL_OPTION );                            
				//JOptionPane.showInternalMessageDialog( this,"Error: \n"+e.toString() );
			}
	}

	public String getTitulo() {
		return "Datos Basicos de Conexion";
	}

	public void setModificable(boolean b) {
		comboFormato.setEnabled(b);
		txtUnidad.setEnabled(b);
		txtSubcuenta.setEnabled(b);
		txtDescripcion.setEnabled(b);
	}

	public void limpiarCampos() {
		txtUnidad.setText("");
		txtSubcuenta.setText("");
		txtDescripcion.setText("");
	}

	public void setFormato(String formato){
		comboFormato.setSelectedItem(formato);
	}
	public String getFormato(){
		return comboFormato.getSelectedItem().toString();
	}
	public String getUnidad(){
		return txtUnidad.getText();
	}

	public String getSubcuenta(){
		return txtSubcuenta.getText();
	}
	
	public String getDescripcion(){
		return txtDescripcion.getText();
	}
	
	public void setUnidad(String unidad){
		txtUnidad.setText(unidad);
                updateUI();
	}
	
	public void setSubcuenta(String subcuenta){
		txtSubcuenta.setText(subcuenta);
                updateUI();
	}

	public void setDescripcion(String descripcion){
		txtDescripcion.setText(descripcion);
                updateUI();
	}

    public void salir() throws Exception {
    }

    public javax.swing.table.AbstractTableModel getClonModelTable_1() throws CloneNotSupportedException{
        return null;
    }

    public javax.swing.table.AbstractTableModel getClonModelTable_2() throws CloneNotSupportedException{
        return null;
    }

    public javax.swing.table.AbstractTableModel getClonModelTable_3() throws CloneNotSupportedException{
        return null;
    }

}
